﻿// // ******************************************************************
// //       /\ /|       @file       SubtitlesService.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-12-31 20:12
// //    *(__\_\        @Copyright  Copyright (c) , 2024-12-25 18:12 Await
// // ******************************************************************

using AutomaticSubtitles.Contracts.Dto;
using AutomaticSubtitles.Contracts.Vo;
using AutomaticSubtitles.Service.Application.Translate.Commands;
using AutomaticSubtitles.Service.Application.Translate.Queries;
using AutomaticSubtitles.Service.Application.Translate.Service.Queries;

namespace AutomaticSubtitles.Service.Services;

/// <summary>
/// 翻译服务
/// </summary>
public class SubtitlesService : BaseService<SubtitlesService>
{
    [EndpointDescription("单条翻译")]
    [Tags("翻译配置")]
    [EndpointName("单条翻译")]
    [EndpointSummary("单条翻译")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<TranslateDto>?>> GetSubtitlesAsync(string languageType, string value,
        string translatedLanguageType)
    {
        var getTranslateQuery = new GetTranslateQuery(languageType, value, translatedLanguageType);
        await PublishAsync(getTranslateQuery);
        return getTranslateQuery.Result.CreateResult();
    }

    [EndpointDescription("单个媒体翻译")]
    [Tags("翻译配置")]
    [EndpointName("单个媒体翻译")]
    [EndpointSummary("单个媒体翻译")]
    [Authorize]
    public async Task<ResponseModel<string?>> MediaTranslation(string id)
    {
        var getTranslateQuery = new GetTranslateMediaTranslationQuery(id);
        await PublishAsync(getTranslateQuery);
        return getTranslateQuery.Result.CreateResult();
    }

    [EndpointDescription("批量翻译")]
    [Tags("翻译配置")]
    [EndpointName("批量翻译")]
    [EndpointSummary("批量翻译")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<TextTranslationDto>>> BatchSubtitlesByListAsync(TextTranslationVo data)
    {
        var getTranslateQuery = new GetSubtitlesByListQuery(data);
        await PublishAsync(getTranslateQuery);
        return getTranslateQuery.Result.CreateResult()!;
    }

    [Tags("翻译配置")]
    [EndpointDescription("获取翻译列表")]
    [EndpointName("获取翻译列表")]
    [EndpointSummary("获取翻译列表有分页")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<TranslateDto>?>> GetTranslateListQuery(
        int page,
        int pageSize)
    {
        var getTranslateQuery = new GetTranslateListQuery(new PaginatedOptions(page, pageSize));
        await PublishAsync(getTranslateQuery);
        return getTranslateQuery.Result.CreateResult();
    }

    [Tags("翻译配置")]
    [EndpointDescription("添加翻译")]
    [EndpointName("添加翻译")]
    [EndpointSummary("添加翻译")]
    [Authorize]
    public async Task<ResponseModel<int>> AddTranslateDataAsync(TranslateVo data)
    {
        var addTranslateCommand = new AddTranslateCommand(data);
        await PublishAsync(addTranslateCommand);
        return addTranslateCommand.Result.CreateResultAdd();
    }

    [Tags("翻译配置")]
    [EndpointDescription("删除翻译")]
    [EndpointName("删除翻译")]
    [EndpointSummary("删除翻译")]
    [Authorize]
    public async Task<ResponseModel<int>> DeleteTranslateDataAsync(string id)
    {
        var deleteTranslateCommand = new DeleteTranslateCommand(id);
        await PublishAsync(deleteTranslateCommand);
        return deleteTranslateCommand.Result.CreateResultDelete();
    }

    [Tags("翻译配置")]
    [EndpointDescription("修改翻译")]
    [EndpointName("修改翻译")]
    [EndpointSummary("修改翻译")]
    [Authorize]
    public async Task<ResponseModel<int>> UpdateTranslateDataAsync(TranslateVo data)
    {
        var updateTranslateCommand = new UpdateTranslateCommand(data);
        await PublishAsync(updateTranslateCommand);
        return updateTranslateCommand.Result.CreateResultUpdate();
    }

}